// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import Fk
import Fk.Components.LunarLTK
import Fk.Pages.LunarLTK
import Fk.Components.Common

GraphicsBox {
  property var options: []
  property var all_options: []
  property string skill_name: ""

  id: root
  title.text: Lua.tr("$Choice").arg(Lua.tr(skill_name))
  width: Math.max(140, body.width + 20)
  height: body.height + title.height + 20

  GridLayout {
    id: body
    x: 10
    y: title.height + 5
    flow: GridLayout.TopToBottom
    rows: 8
    columnSpacing: 10

    Repeater {
      model: all_options

      MetroButton {
        Layout.fillWidth: true
        text: Util.processPrompt(modelData)
        // enabled: options[index] ? options[index][0] === modelData[0] : false
        enabled: {
          for(let i = 0;i < options.length;i++){
            if(options[i] === modelData) {
              return true
            }
          }
          return false
        }

        onClicked: {
          // console.log(index)
          const reply = modelData;
          ClientInstance.replyToServer("", reply);
          close();
          roomScene.state = "notactive";
        }
      }
    }
  }

  function loadData(data) {
    // console.log(data)
    skill_name = data[0];
    // detail_content = data[1];
    options = data[1] ?? [];
    all_options = data[2] ?? [];
  }
}
